/**
 * 
 */
package com.thon.dao.project.impl;


import java.util.List;

import org.springframework.stereotype.Repository;

import com.thon.dao.project.RegionDao;
import com.thon.dao.util.AbstractDao;
import com.thon.dao.util.Page;
import com.thon.entity.project.Region;

/**
 * @file RegionDaoImpl.java
 * @author Zemo
 * @mail zemochen@gmail.com
 * @data 2013年10月11日 上午11:32:53
 * @description: TODO
 */
@Repository
public class RegionDaoImpl extends AbstractDao<Region> implements RegionDao{
	
	public RegionDaoImpl(){
		super(Region.class);
	}
	
	@Override
	public Page<Region> findRegionPage(Page<Region> page) {
		String queryString = "FROM Region";
		return findPage(page, queryString);
	}

	@Override
	public List<Region> listRegions(int parentId) {
		String queryString = "FROM Region r WHERE r.parentId = ? order by r.parentId";
		return findList(queryString, null, parentId);
	}

	@Override
	public List<Region> listRegionsByLevel(Byte level) {
		String queryString = "FROM Region r WHERE r.level = ?";
		return findList(queryString, null, level);
	}

	@Override
	public Page<Region> findRegion(Page<Region> page, Byte level) {
		String queryString = "FROM Region WHERE level = ?";
		return findPage(page, queryString, level);
	}

	@Override
	public List<Region> listRegionById(int id) {
		String queryString = "FROM Region WHERE id = ?";
		return findList(queryString, null, id);
	}

	@Override
	public Region getRegionById(int id) {
		String queryString = "FROM Region WHERE id = ?";
		return findOne(queryString, null, id);
	}
}
